package org.dromara.wms.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.common.web.core.BaseService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.wms.domain.WmsProcess;
import org.dromara.wms.service.WmsProcessService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 工序管理
 *
 * @author wenrui Su
 * @date 2024-05-01
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/wms/process")
public class WmsProcessController extends BaseService {

  private final WmsProcessService wmsProcessService;

/**
 * 查询工序管理列表
 */
@SaCheckPermission("wms:process:list")
@GetMapping("/list")
  public TableDataInfo<WmsProcess> list(WmsProcess bo, PageQuery pageQuery) {
    return wmsProcessService.queryPageList(bo, pageQuery);
  }

  /**
   * 导出工序管理列表
   */
  @SaCheckPermission("wms:process:export")
  @Log(title = "工序管理", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(WmsProcess bo, HttpServletResponse response) {
    List<WmsProcess> list = wmsProcessService.queryList(bo);
    ExcelUtil.exportExcel(list, "工序管理", WmsProcess. class,response);
  }

  /**
   * 获取工序管理详细信息
   *
   * @param id 主键
   */
  @SaCheckPermission("wms:process:query")
  @GetMapping("/{id}")
  public R<WmsProcess> getInfo(@NotNull(message = "主键不能为空")
                                 @PathVariable Long id) {
    return R.ok(wmsProcessService.queryById(id));
  }

  /**
   * 新增工序管理
   */
  @SaCheckPermission("wms:process:add")
  @Log(title = "工序管理", businessType = BusinessType.INSERT)
  @RepeatSubmit()
  @PostMapping()
  public R<Void> add(@Validated(AddGroup.class) @RequestBody WmsProcess bo) {
    return toAjax(wmsProcessService.insertByBo(bo));
  }

  /**
   * 修改工序管理
   */
  @SaCheckPermission("wms:process:edit")
  @Log(title = "工序管理", businessType = BusinessType.UPDATE)
  @RepeatSubmit()
  @PutMapping()
  public R<Void> edit(@Validated(EditGroup.class) @RequestBody WmsProcess bo) {
    return toAjax(wmsProcessService.updateByBo(bo));
  }

  /**
   * 删除工序管理
   *
   * @param ids 主键串
   */
  @SaCheckPermission("wms:process:remove")
  @Log(title = "工序管理", businessType = BusinessType.DELETE)
  @DeleteMapping("/{ids}")
  public R<Void> remove(@NotEmpty(message = "主键不能为空")
                        @PathVariable Long[] ids) {
    return toAjax(wmsProcessService.deleteWithValidByIds(List.of(ids), true));
  }
}
